﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using DryIoc;
using HandyControl.Tools.Extension;
using IntoTheVoid.Models;
using IntoTheVoid.Units;
using IntoTheVoid.ViewModels;
using Application = System.Windows.Application;
using Binding = System.Windows.Data.Binding;

namespace IntoTheVoid
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainView : Window
	{
		public NotifyIcon notifyIcon;

		public MainView()
		{
			InitializeComponent();
			this.DataContext = new MainViewModel(this);
			InitIcon();

			Application.Current.Exit += (sender, e) =>
			{
				notifyIcon.Visible = false;
				notifyIcon.Icon = null;
				notifyIcon.Dispose();
				Environment.Exit(0);
			};
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			WindowState = WindowState.Minimized;
		}

		private void Border_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
		{
			if (e.LeftButton == MouseButtonState.Pressed)
				this.DragMove();

		}

		private void Button_Close(object sender, RoutedEventArgs e)
		{

			var isClose = BaseInfoContentModel.Instance.GetValue<int>("setCloseWindowType", 0);
			if (isClose == 0)
			{
				notifyIcon.Visible = false;
				notifyIcon.Icon = null;
				notifyIcon.Dispose();
			//	this.Close();
				Application.Current.Shutdown();

			}
			else
			{
				this.WindowState = WindowState.Minimized;
				this.Hide();
			}
		}

		public void Window_Closing(object sender, EventArgs e)
		{
			WindowClose();
		}


		public void WindowClose()
		{
			System.Windows.Application.Current.Shutdown();
		}

		private void Window_Showing(object sender, EventArgs e)
		{
			this.Show();
			this.WindowState = WindowState.Normal;
		}

		private void InitIcon()
		{
			notifyIcon = new NotifyIcon();
			notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
			notifyIcon.Text = "IntoTheVoid";
			notifyIcon.Visible = true;

			ToolStripMenuItem menuItem1 = new ToolStripMenuItem("打开主窗口");
			menuItem1.Click += Window_Showing;

			System.Windows.Forms.ToolStripMenuItem menuItem2 = new ToolStripMenuItem("退出");
			menuItem2.Click += Window_Closing;

			ContextMenuStrip cms = new ContextMenuStrip();
			cms.Items.Add(menuItem1);
			cms.Items.Add(menuItem2);

			notifyIcon.ContextMenuStrip = cms;
			notifyIcon.DoubleClick += Window_Showing;

		}

		private void ImageButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			QQ_QRcode.Show();
			pop1.IsOpen = true;
		}

		private void ImageButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			//QQ_QRcode.Hide();
			// QQ_QRcode.Show();
			pop1.IsOpen = false;
		}

		private void ImageButton_Click(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process.Start("http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=-qumCS3Q4WFYmQuc6xMYfX18isWk1EtO&authKey=6nUduNj8XMW9rza9vQQyaZIt%2FUtBPsHxK82%2ByLp4cK9%2BOkL%2B9NKkqdTuckPUito8&noverify=0&group_code=667151873");

		}
		private void QAImageButton_Click(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process.Start("https://qm.qq.com/q/U6X2e4jgIM");

		}
		private void QAButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			pop2.IsOpen = true;
			// pop3.IsOpen = true;
		}

		private void QAButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			pop2.IsOpen = false;
			// pop3.IsOpen = false;

		}
		private void TapTapButton_Click(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process.Start("https://www.taptap.cn/app/273409");

		}
		private void WeiboButton_Click(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process.Start("https://weibo.com/u/7374917256");

		}
		private void BilibiliButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			// pop2.IsOpen = true;
			// pop3.IsOpen = true;
		}

		private void BilibiliButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			// pop2.IsOpen = false;
			// pop3.IsOpen = false;

		}
		private void TapButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			pop3.IsOpen = true;
		}

		private void TapButton_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			pop3.IsOpen = false;

		}
		private void ImageButton_Click_1(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process.Start("https://www.taptap.cn/moment/522171643934542530");

		}

		private void BilibiliButton_Click(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process.Start("https://space.bilibili.com/1941197170/");
		}

		private void TitlePopupShow1(object sender, System.Windows.Input.MouseEventArgs e)
		{
			var model = (MainViewModel)DataContext;
			if(model.AdvertShowTitleOrg1 != model.AdvertShowTitle1 && TitlePopupButton1.Visibility == Visibility.Visible)
			{
				AdvertShow1.Visibility = Visibility.Visible;
			}
		}
		private void TitlePopupHide1(object sender, System.Windows.Input.MouseEventArgs e)
		{
			AdvertShow1.Visibility = Visibility.Hidden;
		}

		private void TitlePopupShow2(object sender, System.Windows.Input.MouseEventArgs e)
		{
			var model = (MainViewModel)DataContext;
			if (model.AdvertShowTitleOrg2 != model.AdvertShowTitle2 && TitlePopupButton2.Visibility == Visibility.Visible)
			{
				AdvertShow2.Visibility = Visibility.Visible;
			}
		}
		private void TitlePopupHide2(object sender, System.Windows.Input.MouseEventArgs e)
		{
			AdvertShow2.Visibility = Visibility.Hidden;

		}

	}
}
